/**
 * 
 */
package data;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import com.google.inject.internal.Lists;

/**
 * @author <a href="www.sureinterview.com">SureInterview</a>
 */
public class Data {
	static public String getData(String name) {
		InputStream is = Data.class.getResourceAsStream(name);
		StringBuffer sb = new StringBuffer();
		try {
			int n = 0;
			while ((n = is.read()) > 0) {
				sb.append((char) n);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return sb.toString();
	}

	static public List<List<String>> getDataAsList(String name) {
		InputStream is = Data.class.getResourceAsStream(name);
		StringBuffer sb = new StringBuffer();
		try {
			int n = 0;
			while ((n = is.read()) > 0) {
				sb.append((char) n);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		String[] lines = sb.toString().split("\n+");
		List<List<String>> data = new ArrayList<List<String>>();

		int lineNum = Integer.valueOf(lines[0]);
		for (int i = 1; i <= lineNum; i++) {
			List<String> ln = Lists.newArrayList(lines[i].split(" +"));
			data.add(ln);
		}

		return data;
	}
}
